/*This script performs the main analyses for the proof-of-concept study in Section 4
of the Cambridge Elements.*/

//We used Stata/SE 18.0 for Mac (Intel 64-bit), Revision 25 Apr 2023



//////////////////////////////////////////
//Testing hypotheses on constituent side
//////////////////////////////////////////

//Load analysis dataset
use "analysis_dataset_constituents.dta", clear

//Test Hypothesis H1a
reg surrogation_dimension female_local_MP age uni_degree left_right i.referendum i.party_close copartisan unemployment_local standing_down_local if female == 1, vce(cluster local_MP)
outreg using "./Tables and Figures/Table3.doc", replace starlevels(5 1) se

//Plot effect
margins, at(female_local_MP = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) xtitle("") ytitle("{bf:Female voters' surrogation demand}", size(medium)) xlab(0 `""{bf:Local MP}" "{bf:is male}""' 1 `""{bf:Local MP}" "{bf:is female}""') ylab(0.5 1 1.5) title("{bf:Hypothesis H1a}", size(large))
graph save "./Tables and Figures/H1a.gph", replace
graph export "./Tables and Figures/H1a.png", height(1500) replace

//Test Hypothesis H2a
reg justification_dimension female_chosen_MP age uni_degree left_right i.referendum i.party_close unemployment_representative if female == 1, vce(cluster representative)
outreg using "./Tables and Figures/Table3.doc", merge starlevels(5 1) se

//Plot effect
margins, at(female_chosen_MP = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) xtitle("") ytitle("{bf:Female voters' justification demand}", size(medium)) xlab(0 `""{bf:Chosen MP}" "{bf:is male}""' 1 `""{bf:Chosen MP}" "{bf:is female}""') title("{bf:Hypothesis H2a}", size(large))
graph save "./Tables and Figures/H2a.gph", replace
graph export "./Tables and Figures/H2a.png", height(1500) replace

//Test Hypothesis H3a
reg personalization_dimension female_chosen_MP age uni_degree left_right i.referendum i.party_close unemployment_representative i.party_whip_enc if female == 1 & party_whip_enc != 4, vce(cluster representative)
outreg using "./Tables and Figures/Table3.doc", merge starlevels(5 1) se

//Plot effect
margins, at(female_chosen_MP = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) xtitle("") ytitle("{bf:Female voters' personalization demand}", size(medium)) xlab(0 `""{bf:Chosen MP}" "{bf:is male}""' 1 `""{bf:Chosen MP}" "{bf:is female}""') title("{bf:Hypothesis H3a}", size(large))
graph save "./Tables and Figures/H3a.gph", replace
graph export "./Tables and Figures/H3a.png", height(1500) replace

//Test Hypothesis H4a
reg responsiveness_dimension female_chosen_MP age uni_degree left_right i.referendum i.party_close unemployment_representative standing_down_representative if female == 1, vce(cluster representative)
outreg using "./Tables and Figures/Table3.doc", merge starlevels(5 1) se

//Plot effect
margins, at(female_chosen_MP = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) title("") xtitle("") ytitle("{bf:Female voters' responsiveness demand}", size(medium)) xlab(0 `""{bf:Chosen MP}" "{bf:is male}""' 1 `""{bf:Chosen MP}" "{bf:is female}""') title("{bf:Hypothesis H4a}", size(large))
graph save "./Tables and Figures/H4a.gph", replace 
graph export "./Tables and Figures/H4a.png", height(1500) replace

//Combined graph
graph combine "./Tables and Figures/H1a.gph" "./Tables and Figures/H2a.gph" "./Tables and Figures/H3a.gph" "./Tables and Figures/H4a.gph", altshrink ysize(18) xsize(14) scheme(lean2)
graph export "./Tables and Figures/Figure10.png", height(3000) replace



/////////////////////////////////////////////
//Testing hypotheses on representative side
/////////////////////////////////////////////

//Load analysis dataset
use "analysis_dataset_representatives.dta", clear

//Test Hypothesis H1b
reg women_local gender_MP_enc ws_left_right i.party_enc unemployment brexit_vote 
outreg using "./Tables and Figures/Table4.doc", replace starlevels(5 1) se

//Plot effect
margins, at(gender_MP_enc = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) xtitle("") ytitle("{bf:MP's attention to women vs. constituency (number of words)}", size(medium)) xlab(0 "{bf:Male MPs}" 1 "{bf:Female MPs}") title("{bf:Hypothesis H1b}", size(large))
graph save "./Tables and Figures/H1b.gph", replace
graph export "./Tables and Figures/H1b.png", height(1500) replace

//Test Hypothesis H2b
reg scores_mean_plu gender_MP_enc ws_left_right i.party_enc unemployment brexit_vote 
outreg using "./Tables and Figures/Table4.doc", merge starlevels(5 1) se

//Plot effect
margins, at(gender_MP_enc = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) xtitle("") ytitle("{bf:MP's pluralist justification score (word embeddings)}", size(medium)) xlab(0 "{bf:Male MPs}" 1 "{bf:Female MPs}") title("{bf:Hypothesis H2b}", size(large))
graph save "./Tables and Figures/H2b.gph", replace
graph export "./Tables and Figures/H2b.png", height(1500) replace

//Test Hypothesis H3b
reg rebellion gender_MP_enc ws_left_right i.party_enc unemployment brexit_vote  if party_enc != 4
outreg using "./Tables and Figures/Table4.doc", merge starlevels(5 1) se

//Plot effect
margins, at(gender_MP_enc = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) xtitle("") ytitle("{bf:MP's rate of rebellion (% of HoC divisions)}", size(medium)) xlab(0 "{bf:Male MPs}" 1 "{bf:Female MPs}") title("{bf:Hypothesis H3b}", size(large))
graph save "./Tables and Figures/H3b.gph", replace
graph export "./Tables and Figures/H3b.png", height(1500) replace

//Test Hypothesis H4b
reg responsiveness gender_MP_enc ws_left_right i.party_enc unemployment 
outreg using "./Tables and Figures/Table4.doc", merge starlevels(5 1) se

//Plot effect
margins, at(gender_MP_enc = (0 1))
marginsplot, scheme(lean2) recast(scatter) ylabel(,glcolor(none) glwidth(vvthin)) xscale(range(-0.5 1.5)) title("") xtitle("") ytitle("{bf:MP's irresponsiveness on Brexit (IRT model)}", size(medium)) xlab(0 "{bf:Male MPs}" 1 "{bf:Female MPs}") title("{bf:Hypothesis H4b}", size(large))
graph save "./Tables and Figures/H4b.gph", replace
graph export "./Tables and Figures/H4b.png", height(1500) replace

//Combined graph
graph combine "./Tables and Figures/H1b.gph" "./Tables and Figures/H2b.gph" "./Tables and Figures/H3b.gph" "./Tables and Figures/H4b.gph", altshrink ysize(18) xsize(14) scheme(lean2)
graph export "./Tables and Figures/Figure11.png", height(3000) replace



/////////////////////
//Robustness checks
/////////////////////

//Load analysis dataset
use "analysis_dataset_constituents.dta", clear

//Test Hypothesis H3a including respondents who identify with independent MPs
reg personalization_dimension female_chosen_MP age uni_degree left_right i.referendum i.party_close unemployment_representative i.party_whip_enc if female == 1, vce(cluster representative)

//Load analysis dataset
use "analysis_dataset_representatives.dta", clear

//Test Hypothesis H2b with alternative measure (republican-pluralist)
reg scores_rep_plu_scale gender_MP_enc ws_left_right i.party_enc unemployment brexit_vote 
cor scores_rep_plu_scale scores_mean_plu
